import time

from django.http import JsonResponse
from django.shortcuts import render
from Files import models
# Create your views here.
from django.views.decorators.csrf import csrf_exempt




@csrf_exempt
def uploadImg(request):
    if request.method == 'POST':
        response = {'status': "200", 'msg': '上传成功'}
        try:
            data = {'img': request.FILES.get('img'), 'name': request.FILES.get('img').name}
            Insert = models.Img.objects.create(**data)
            jsondata = {'img':str(Insert.img),'path':'/media/'+str(Insert.img),'name':Insert.name}
            response['data'] = jsondata
            print(response)
        except Exception as e:
            print(e)
            response['status'] = "201"
            response['msg'] = "上传失败"
    return JsonResponse(response,safe=False)

